package com.burger.counter.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.burger.counter.beans.Starter;
import com.burger.counter.business.StarterBusiness;

/**
 * Servlet implementation class StarterServlet
 */
public class StarterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public StarterServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try
		{
			doPost(request, response);
		}
		catch(Exception e)
		{
			System.err.println(e);
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		try
		{
			// Getting data to starter Menu Option
			StarterBusiness starterBI = new StarterBusiness();
			Starter starterList[] =null;
			HttpSession session = request.getSession(true);
			
			Integer regionData =(Integer)session.getAttribute("RegionId");
			
			try {
				starterList = starterBI.getStarterDetails(regionData);
			} 
			catch (Exception e) {
				e.printStackTrace();
			}
						
			request.getSession().setAttribute("StarterList", starterList);
			
			RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/StarterMenu.jsp");
			dispatcher.forward(request, response);
			
		}
		catch(Exception e)
		{
			System.err.println(e);
		}
		
	}

}
